<?php

namespace App\Models\Send;

use Illuminate\Database\Eloquent\Model;

class SysSendTypeExpenditure extends Model
{
    protected $table = 'sys_send_type_expenditure';

    protected $primaryKey = 'id';

    public $timestamps = false;

    public $incrementing = false;

    /**
     * 自定义运费（缓存）
     * @param int $id
     * @return null|array
     */
    public static function getCache( $id )
    {

        if ( !isset( $sendTypeID ) || !ebsig_is_int( $sendTypeID ) ) {
            return null;
        }

        $cache_data = json_decode(Redis::get('WDH_SEND_ZDYFY_' . $sendTypeID), true);
        if ( $cache_data ) {
            return $cache_data;
        }

        $expenditure_data = self::find($sendTypeID);
        if ( !$expenditure_data ) {
            return null;
        }
        $expenditure_data = $expenditure_data->toArray();

        $cache_data = [
            'id' => $expenditure_data['id'],
            'title' => $expenditure_data['title'],
            'is_use' => $expenditure_data['is_use'],
            'limit_amount' => $expenditure_data['limit_amount'],
            'amount' => $expenditure_data['amount'],
        ];

        Redis::set('WDH_SEND_ZDYFY_' . $sendTypeID, json_encode($cache_data));

        return $cache_data;

    }

}
